Sequential (learning notes), sequential learning notesFunctions of Sequences
In many databases, users are provided with a Sequence of auto-increment columns, which can be automatically numbered based on specified rules.
Complete Sequence creation syntax
Create sequence name [increment by step] [start with start value] [MAXVALUE maximum value | NOMAXVALUE] [MINVALUE minimum value | NOMINVALUE] [CYCLE | NOCYCLE] [CACHE size | NOCACHE];
Create default sequence syntaxCreate sequence name
Example 1,C
1. the auto-Increment Function in Oracle can only be completed by sequence. All auto-increment operations must be completed by the user. Sequence creation format: [SQL] CREATE SEQUENCE sequence [INCREMENT BY n] [STARTWITH n] [{MAXVALUE n | NOMAXVALUE}] [{MINVALUE n | NOMINVALUE}] [{CYCLE | NOCYCLE}] [{ CACHE n | NOCACHE}]; example of www.2cto.com: Create a sequence of myseq to verify auto-increment operations. [SQL] CREATE SEQUENCE
1. Knowledge Points: Can be read against the following record screen view, sequence, index, Synonym Sql>--view: Virtual table sql>--View advantages: Simplify complex queries, limit data access (more banks), provide independent data, the same data can be displayed differently sql>-first view: Employee number name annual salary sql> Create VIEW View1 2 as 3 select Empno,ename,sal,sal*12 annlsal from EMP; Sql>--If the display does not have permissions, you need authorization, see 1-1sql>--Complex
see the active standbys on these two interfaces.Information.Traxbol # debug serial interfaceSerial network interface debugging is onTraxbol #* Mar 8 09:42:34. 851: Serial0: HDLC myseq 28, mineseen 28 *, yourseen 41, line up! -- Enable HDLC on Serial 0* Mar 8 09:42:34. 855: seri_3: HDLC myseq 26, mineseen 26 *, yourseen 27, line up! -- The HDLC on Serial 3 is active* Mar 8 09:42:44. 851: Serial0: HDLC
numbers.NOCACHE: serial numbers are not generated in memory in advance.
Case 2: Create a sequence starting from 1, with the default maximum value increasing by 1 each time. NOCYCLE is required, and the cache contains 30 pre-allocated serial numbers.
Code Demonstration: generate a serial number
SQL> CREATE SEQUENCE MYSEQMINVALUE 1Start with 1NOMAXVALUEIncrement by 1NOCYCLECACHE 30/
Sequence created
After creating a sequence, you can access the current value and the next value of the sequence th
value is not guaranteed.
4. Delete Sequence
2 format:
Drop sequence name
5. Management Sequence
2 format:
Alter sequence name
[Increment by n2]
[Minvalue n3 | nominvalue]
[Maxvalue n4 | nomaxvalue]
[Cache n5 | Nocache]
[Cycle | nocycle]
[Order | noorder]
Note: Except for the starting value of a sequence, other sequence clauses and parameters that can be set can be modified. After the sequence is modified, all the sequence values in the cache will be lost. You can obtain the sequence information
FUNCTION currval (seq_name VARCHAR ()) RETURNS BIGINT BEGIN
DECLARE value BIGINT; SELECT current_value into value from sequence WHERE upper (name) = Upper (Seq_name);
--The case does not differentiate.
return value;
End;
/DELIMITER;
Delimiter/drop function IF EXISTS nextval/create FUNCTION nextval (seq_name VARCHAR ()) RETURNS BIGINT BEGIN
DECLARE value BIGINT;
UPDATE sequence SET current_value = current_value + increment WHERE upper (name) = Upper (Seq_name);
Re
CREATE TABLETables ([SID] [Numeric]( A,0)IDENTITY(1,1) not NULL, [UpdateTime] [datetime] not NULL, CONSTRAINT [Pk_tables] PRIMARY KEY(SIDASC) ) Use this statement to create a table to hold an ID. declare @myseq numeric (12 ) insert into Tables (updatetime) values ( getdate set @myseq = scope_identity () delete from Tables where sid= @myseq
export the select result to a text file?Spool/home/Winnie/test.txt;Select * From mytable;Spool off;
11. rowid returns the physical address of the rowSelect rowid from mytable;
Rowid
------------------
Aaactgaakaaabd8aaa
Aaactgaakaaabd8aab
12. currval and nextval create sequence for the table
Create sequence myseq start with 1 increment by 1;
Select myseq. currval from dual;
Insert into mytable values (
Outer Join: The left table is completely displayed, and the right side is matched by conditions.Select Stu. Name, Stu. ID, exam. grade from Stu left join exam on Stu. ID = exam. ID;Or:Select Stu. Name, Stu. ID, exam. grade from Stu, exam where Stu. ID = exam. ID (+ );2 -- right outer join: The right table is completely displayed, and the left table is matched by conditions.Select Stu. Name, Stu. ID, exam. grade from Stu right join exam on Stu. ID = exam. ID;Or:Select Stu. Name, Stu. ID, exam. g
, which is mainly for the convenience of development, the syntax for creating sequences is as follows: CREATE SEQUENCE SEQUENCE [INCREMENT by N] [START with N] [{MAXVALUE n| Nomaxvalue}] [{MINVALUE n| Nominvalue}] [{cycle| Nocycle}] [{CACHE n| NOCACHE}]; Example: Creating a sequence CREATE SEQUENCE Myseq; Once a sequence has been created, the sequence can be accessed in the following two ways:
The sequence name. Nextval: Let the seque
properly. Show Interface Serial0 command indicates that the line protocol is starting normally. Use the Undebug all command to turn off all debugging.
Yh-router#debug Serial Interface
Serial network interface debugging is on
yh-router#
June 1 21:54:55 PDT:Serial0:HDLC myseq 171093, Mineseen 171093*, Yourseen 1256540,line up
June 1 21:55:05 PDT:Serial0:HDLC myseq 171094, Mineseen 171094*, Yourseen 1256
seems to be a change, the follow-up sequence belongs to the creation process of database object, belongs to the classification category of DDL, for the sequence, it will be saved in the data dictionary after creation example:create sequence myseq; Nextval: Gets the next content of the sequence, each time the value of the call sequence grows Currval: Represents the current contents of the acquisition sequence, and each call sequence does not gr
HDLC keeps Active packets exchanged every 10 seconds. This indicates that the link operation is normal and the Layer 2 operation is normal. The show interface serial0 command indicates that the line protocol is started normally. Use the undebug all command to disable all debugging tasks.
YH-Router # debug serial interfaceSerial network interface debugging is onYH-Router #Jun 1 21:54:55 PDT: Serial0: HDLC myseq 171093, mineseen 171093 *, yourseen 1256
indicates that the line protocol is started normally. Use the undebug all command to disable all debugging tasks.
YH-Router # debug serial interfaceSerial network interface debugging is onYH-Router #Jun 1 21:54:55 PDT: Serial0: HDLC myseq 171093, mineseen 171093 *, yourseen 1256540, line upJun 1 21:55:05 PDT: Serial0: HDLC myseq 171094, mineseen 171094 *, yourseen 1256541, line upJun 1 21:54:15 PDT: Serial
indicates that the line protocol is started normally. Use the undebug all command to disable all debugging tasks.
YH-Router#debug serial interfaceSerial network interface debugging is onYH-Router#Jun 1 21:54:55 PDT:Serial0: HDLC myseq 171093, mineseen 171093*, yourseen 1256540,line upJun 1 21:55:05 PDT:Serial0: HDLC myseq 171094, mineseen 171094*, yourseen 1256541,line upJun 1 21:54:15 PDT:Ser
indicates that the line protocol is started normally. Use the undebug all command to disable all debugging tasks.
YH-Router#debug serial interfaceSerial network interface debugging is onYH-Router#Jun 1 21:54:55 PDT:Serial0: HDLC myseq 171093, mineseen 171093*, yourseen 1256540,line upJun 1 21:55:05 PDT:Serial0: HDLC myseq 171094, mineseen 171094*, yourseen 1256541,line upJun 1 21:54:15 PDT:Serial0
Sequence operations in Oracle and use the previous initialization of sequence 1 create sequence myseqstart with 1 increment by 1 nomaxvalueminvalue 1 II Initialize sequence select myseq. nextval from dual; it is worth noting that if you write select myseq directly first. currval from dual, will prompt myseq. currtval has not been defined in this session. Www.2cto
indicates that the line protocol is started normally. Use the undebug all command to disable all debugging tasks.
YH-Router#debug serial interfaceSerial network interface debugging is onYH-Router#Jun 1 21:54:55 PDT:Serial0: HDLC myseq 171093, mineseen 171093*, yourseen 1256540,line upJun 1 21:55:05 PDT:Serial0: HDLC myseq 171094, mineseen 171094*, yourseen 1256541,line upJun 1 21:54:15 PDT:Serial0: HDL
have never used it because it is always troublesome. This project was used, and the video was also described. It was very simple and practical.Syntax:Create sequence myseqIncrement by 1 -- add severalStart with 1 -- count from 1NOMAXVALUE -- do not set the maximum valueNOCYCLE -- always accumulate without repeatingCACHE 10;When used, for example, insert, you only need to assign myseq. NEXTVAL to the corresponding column.For exampleInsert into emp VAL
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.